package com.string_;

import java.util.ArrayList;
import java.util.List;

public class Array2String {
    public static void main(String[] args) {
        //先准备一个List
        List<String> testList = new ArrayList<>();
        testList.add("a");
        testList.add("b");
        testList.add("c");
        System.out.println(getType(testList));
        method01(testList);
        method02(testList);
        test01();
    }

    protected static void method01(List<String> testList) {
        //List转String
        String[] strs1 = testList.toArray(new String[testList.size()]);
        System.out.println("----method1----");
        System.out.println(getType(strs1));
        for (String s : strs1) {
            System.out.println(s);
        }
    }

    protected static void method02(List<String> testList) {
        //List转String
        String[] strs2 = new String[testList.size()];
        for (int i = 0; i < testList.size(); i++) {
            strs2[i] = testList.get(i);
        }
        System.out.println("----method2----");
        for (String s : strs2) {
            System.out.println(s);
        }
    }


    public static String getType(Object o) { //获取变量类型方法
        return o.getClass().toString(); //使用int类型的getClass()方法
    }

    protected static void test01() {
        char[] helloArray = {'r', 'u', 'n', 'o', 'o', 'b'};
        System.out.println(getType(helloArray));
        String helloString = new String(helloArray);
        System.out.println(helloString);
    }

}
